﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using util;
using dto;
using System.Data;
using MySql.Data;
using MySql.Data.MySqlClient;
using common;
namespace dao
{
    public class MultiLanguageDAO
    {
        public DataTable getAllLanguages()
        {
            DataTable dt = new DataTable();
            try
            {
                DataUtil.connect();
                String cmdText = "sp_GetAllLanguages";
                dt = DataUtil.executeStore(cmdText, null);
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            return dt;
        }
        public void getAllLanguageDetailsByLanguageID(String languageID)
        {
            DataTable dt = new DataTable();
            try
            {
                DataUtil.connect();
                String cmdText = "sp_GetAllLanguageDetailsByLanguageID";
                MySqlParameter[] arrParam = new MySqlParameter[1];
                arrParam[0] = new MySqlParameter("_LanguageID", languageID);
                MySqlDataReader reader = DataUtil.executeReader(cmdText, arrParam);
                DataRow row = dt.NewRow();
                int i = 0;
                while(reader.Read())
                {
                    dt.Columns.Add(reader["Variable"].ToString());
                    row[i] = reader["Content"].ToString();
                    i++;
                }
                dt.Rows.Add(row);
                Constant.DT_LABLE = dt;
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            DataUtil.disconnect();
        }
        public void getAllMessageDetailsByLanguageID(String languageID)
        {
            DataTable dt = new DataTable();
            try
            {
                DataUtil.connect();
                String cmdText = "sp_GetAllMessageDetailsByLanguageID";
                MySqlParameter[] arrParam = new MySqlParameter[1];
                arrParam[0] = new MySqlParameter("_LanguageID", languageID);
                MySqlDataReader reader = DataUtil.executeReader(cmdText, arrParam);
                DataRow row1 = dt.NewRow();
                DataRow row2 = dt.NewRow();
                int i = 0;
                while (reader.Read())
                {
                    dt.Columns.Add(reader["Variable"].ToString());
                    row1[i] = reader["ID"].ToString();
                    row2[i] = reader["Content"].ToString();
                    
                    i++;
                }
                dt.Rows.Add(row1);
                dt.Rows.Add(row2);
                Constant.DT_MESSAGE = dt;
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            DataUtil.disconnect();
        }
        public DataTable getMultiLanguageByXMLFile()
        {
            try
            {
                DataTable dt = new DataTable();
                DataSet ds = new DataSet("language");
                String filePath = "languageGTVAccountingSystem\\MultiLanguage.xml";
                ds.ReadXml(filePath);
                
                return ds.Tables[0];
            }
            catch (Exception ex)
            {
                return null;
            }
        }
    }

}
